package www.huiting.user.service.impl;

import lombok.extern.java.Log;
import lombok.extern.log4j.Log4j2;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.StatusRpcException;
import org.apache.dubbo.rpc.TriRpcStatus;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import www.huiting.user.service.*;

import java.util.List;

import static org.apache.dubbo.rpc.RpcException.BIZ_EXCEPTION;
@Log4j2
@DubboService
public class UserService extends IUserService {


    @Override
    public Mono<List<String>> getList() {
        return Mono.just(List.of("用户1","用户2"));
    }
    //注意点，proto文件不能直接再rest中返回
    @Override
    public Mono<GreeterReply> getUserById(Mono<GreeterRequest> reactorRequest) {

 //       return Mono.error(new StatusRpcException(TriRpcStatus.UNKNOWN.withDescription("test exception")));
        return Mono.just(GreeterReply.newBuilder().setMessage("用户1").build()).map(v->{
            if(true){
                log.error("用户不存在,抛出异常");
                throw new StatusRpcException(TriRpcStatus.UNKNOWN.withDescription("用户不存在"));
            }

            return v;
        });
    }

    @Override
    public Flux<GreeterReply> getUserListById(Mono<GreeterRequest> reactorRequest) {
        return null;
    }


}
